#pragma once

#include <stdlib.h>
#include <string.h>
#include <vector>
#include <render/Others/PerseusLibDefines.h>

namespace pwp {

template <typename T>
class Image {
public:
  int width, height;

  std::vector<T> buff;
  T* pixels() { return buff.data(); }

  Image(int width, int height) {
    this->width = width;
    this->height = height;

    buff.resize(width * height);

    Clear();
  }

  T &operator[](unsigned subscript) { return buff[subscript]; }
  T operator[](unsigned subscript) const { return buff[subscript]; }

  T& operator()(int ix, int iy) {
    return buff[ix + iy * width];
  }
  T operator()(int ix, int iy) const {
    return buff[ix + iy * width];
  }

  void Clear(T value = T(0)) {
    std::fill(buff.begin(), buff.end(), value);
  }
};

using ImageUChar = Image<unsigned char>;
using ImageInt = Image<int>;
using ImageFloat = Image<float>;
using ImageUInt = Image<unsigned int>;
using ImageBool = Image<bool>;

}
